<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsplib/pubhead.jsp"%>
<%@ page import="net.comm.shequ.service.impl.ShequServiceImpl" %>
<%@ page import="net.comm.shequ.bean.BaseShequ" %>
<%@ page import="net.comm.shequ.web.form.ShequForm" %>
<%@ page import="net.comm.page.PageCtr" %>
<%@ page import="net.comm.common.ReturnMessage" %>
<%@ page import="java.util.List" %>

<% 
		try {
			request.setCharacterEncoding("UTF-8"); 
			response.setCharacterEncoding("UTF-8"); 
		} catch (Exception e) {
			e.printStackTrace();
		}
		//不缓存页面
		response.setHeader("Cache-Control","no-store");
		response.setHeader("Pragrma","no-cache");
		response.setDateHeader("Expires",0);

		String village = request.getParameter("q");
		village = new String(village.getBytes("iso-8859-1"),"utf-8");

		if(village == null || village.equals("")){
		
			village = "";
		}

		int ret = 0;

		StringBuffer sb = new StringBuffer(); 
		response.addHeader("Content-Type","text/html"); 
		
		ShequServiceImpl service = new ShequServiceImpl();
		ShequForm shequform = new ShequForm();
		ReturnMessage msg  = new ReturnMessage();
			
		if(!village.equals("")){
			shequform.setVillage(village);
		}
		shequform.setPage(new PageCtr(1, 10, "N", " 1=1 "));
					
		//查询条件
		List list = service.adlist(shequform,msg);

		if(list.size() > 0){

			sb.append("[");
			int len = list.size();
			BaseShequ base = new BaseShequ();

			for(int i=0; i < len; i++){
				base = (BaseShequ)list.get(i);
				sb.append("{ name: " + "\'" + base.getVillage() + "\'" + ", id: " 
					+ "\'"+ base.getVillageID()+"\'" + "}");
				if(i < len-1){
					sb.append(",");
				}
			}
			sb.append("]");
		}else{
			sb.append("[]");
		}

//		System.out.println("s="+ sb.toString());

		response.getWriter().write(sb.toString()); 		
 %>       
